home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6826 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: C constant expression declarations
  5. Date: 15 Feb 1996 07:57:31 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4fvl5cINN94q@keats.ugrad.cs.ubc.ca>
  8. References: <31229735.41C67EA6@isi.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <31229735.41C67EA6@isi.com>, J.R. Stoner <jstoner@isi.com> wrote:
  12. >This is a query (I have checked the FAQ) into something that strikes me
  13. >as a dumbfoundedly stupid issue, but I will ask it anyway :)
  14. >
  15. >Normally, I will do things such as:
  16. >
  17. > #define EXPR1   1
  18. > #define EXPR2   2
  19. >
  20. >...and so on.  Lately, I have been observing in code from other people
  21. >equivalent declarations such as:
  22. >
  23. > #define EXPR1   (1)
  24. > #define EXPR2   (2)
  25.  
  26. This does not buy you anything at all, since the thing you are bracketing
  27. has only one constituent: it's not a compound expression.
  28.  
  29. It's useful when you define macros for entire expressions, because it ensures
  30. that the expression will always parse as a unit, taking precedence over any
  31. surrounding operators that may appear alongside the macro expansion.
  32.  
  33. >I have seen in the FAQ the business of declaring varargs macros that
  34. >are invoked with something like:
  35. >
  36. > DEBUG(("This is a printf string\n"))
  37. >
  38. >...but it does not seem relevant here.
  39.  
  40. It is. Without the double parentheses, you would not be able to do multiple
  41. arguments. That is, writing
  42.  
  43.     DEBUG("Error %d writing to toaster %d!\n",err,toa)
  44.  
  45. would be interpreted as passing three arguments to the DEBUG macro.
  46. On the other hand, the _single_ argument of
  47.  
  48.     DEBUG(("Error %d writing to toaster %d!\n",err,toa))
  49.  
  50. expands as ("error %d ... \n",err,toa), which can be glued behind, say, a
  51. printf.
  52.  
  53. >Is there, in fact, a reason for putting parens around "simple" constant
  54. >expressions?  A reason that did not exist previously?
  55.  
  56. Absolutely not. Some programmers just become irrationally paranoid over the
  57. years. It's easier to just put parentheses around everything than to think
  58. about it.
  59.  
  60. On the other hand, I'm a minimalist. I tend to eliminate parens as much as
  61. possible to the point that some compilers warn me to put the damn things back
  62. in for clarity. :)
  63. -- 
  64.  
  65.